/*
 * @lc app=leetcode.cn id=559 lang=javascript
 *
 * [559] N叉树的最大深度
 */

// @lc code=start
/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node} root
 * @return {number}
 */
var maxDepth = function (root) {
    if (!root) return 0
    let queue=[root]
    let leave=0
    while(queue.length){
        let len=queue.length
        while(len--){
            let node=queue.shift()
            if(node.children){
                queue=queue.concat(node.children)
            }
        }
        leave++
    }
    return leave
};
// @lc code=end

var maxDepth = function (root) {
    if (!root) return 0
    let max=0
    if (root.children) {
        for (let i in root.children) {
            let num=maxDepth(root.children[i])
            max=Math.max(max,num)
        }
    }
    return max + 1
};//dfs